<template>
  <van-cell
    class="comment-item"
    title-class="comment-title"
    value-class="comment-value"
  >
    <div class="comment-like">
      {{ likeCount }}
      <van-icon
        @click="() => $emit('onLike')"
        :name="`good-job${ isLiked ? '' : '-o' }`"
      />
    </div>
    <template #title>
      <img class="avatar" :src="avatarURL" alt="">
      <div class="info">
        <div class="author">{{ author }}</div>
        <div class="content">{{ content }}</div>
        <div class="comment-btn-wrapper">
          <van-button
            round
            type="default"
            color="#e9e9e9"
            size="mini"
            class="comment-btn"
          >
            {{ replyCount }}回复
            <van-icon name="arrow" />
          </van-button>
          <span class="comment-time">{{ getTime() }}</span>
        </div>
      </div>
    </template>
  </van-cell>
</template>

<script>
import moment from 'moment';

export default {
  props: {
    // id: String,
    // 点赞数量
    likeCount: Number,
    // 头像地址
    avatarURL: String,
    // 作者名字
    author: String,
    // 评论内容
    content: String,
    // 回复数量
    replyCount: Number,
    // 时间戳
    timestamp: String, // to do
    // 是否点赞
    isLiked: Boolean,
  },
  methods: {
    getTime () {
      return moment(this.timestamp).toNow(true) + '内';
    },
  },
}
</script>

<style lang="less" scoped>
.comment-item {
  padding: 8px 0;

  .comment-title {
    // overflow: hidden;
    display: grid;
    grid-template-columns: 32px 1fr;
    grid-gap: 16px;

    .avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
    }

    .comment-content {
      color: #aaa;
    }

    .comment-btn-wrapper {
      display: flex;
      align-items: center;

      .comment-btn {
        color: #000 !important;
      }

      .comment-time {
        margin-left: 8px;
        color: #ccc;
      }
    }

  }

  .comment-value {
    flex: none;
  }
}
</style>